<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>帮帮网</title>
<link href="default.css" media="screen" rel="stylesheet" />
<script type="text/javascript" src="JS/prototype.js"></script>
<script type="text/javascript" src="JS/httpRequest.js"></script>
<script type="text/javascript" src="JS/cookie.js"></script>
<script type="text/javascript" >
function Register()
{
	
	if(CheckUsername() && CheckPwd() && CheckPwd2() && CheckQQ() && CheckCellphone() )
	{
	  var username=$('txtUsername').value;
	  var pwd=$('txtPwd').value;
	  var qq=$('QQ').value;
	  var cellphone=$('cellphone').value;
	  var sex = $('sex').value;
	  var emot = $('emot').value;
	  var college = $('college').value;
	  var regbirthyear=$('regbirthyear').value;
	  var regbirthmonth=$('regbirthmonth').value;
	  var regbirthday=$('regbirthday').value;

	  var url="user/user.php?action=AddUser";	  
	  var para="username="+username;
	  para+="&password="+pwd;	
	  para+="&qq="+qq;
	  para+="&cellphone="+cellphone;
	  para+="&sex="+sex;
	  para+="&emot="+emot;
	  para+="&college="+college;	  
	  para+="&year="+regbirthyear;
	  para+="&month="+regbirthmonth;
	  para+="&day="+regbirthday;
	  response=SendPostRequest(url,para); 	  
	  //alert(response);
	  if(response!="false")
	  {	
		//写入cookie
		document.cookie="username"+"="+username+";path=/;";
		document.cookie="userID"+"="+response+";path=/;";
		if (username!=null || username!="")
		{
			alert('Welcome again '+username+'! 每天都登陆的话 会增加您的活跃度 但是一天之中反复登陆是没有用的哦')
		}
		else
		{
			alert('???');
		}
		//跳转到首页
		window.location.href="myspace.html";

		return false;
	  }
	  else
		alert('注册失败 请重新注册');
	}	  	 

}
function CheckUsername()
{
	var txtUsername=document.getElementById('txtUsername');
	var username=txtUsername.value;
	if(username==null ||username=="")
	{
		$('nameWarn').innerHTML="用户名不能为空!";
		return false ;
	}
	else
	{
	  var url="user.php?action=CheckUser";	  
	  var para="username="+username;
	  response=SendPostRequest(url,para); 	
	  if(response=="false")
	  {
		 $('nameWarn').innerHTML="用户名已存在，请用其他用户名!";
		 return false ;
	  }
	  else
	  {
		  $('nameWarn').innerHTML="ok";
		   return true;
	  }
	 
	  
	}
}

function CheckPwd()
{
	var pwd=document.getElementById('txtPwd').value;
	if(pwd==null || pwd=="")
	{
		$('pwdWarn').innerHTML="密码不能为空!";
		return false ;
	}
	else
	{
		$('pwdWarn').innerHTML="ok";
	    return true;
	}
}

function CheckPwd2()
{
	var pwd=document.getElementById('txtPwd').value;
	var pwd2=document.getElementById('txtPwd2').value;
	if(pwd2==null || pwd2=="")
	{	
	   $('pwd2Warn').innerHTML="密码不能为空!";	
		return false;
	}
	if(pwd2!=pwd)
	{	
	   $('pwd2Warn').innerHTML="密码不一致!";	
		return false;
	}
	else
	{
		$('pwd2Warn').innerHTML="ok";
		return true;
	}
	
}
function CheckQQ()
{
	var QQ=document.getElementById('QQ').value;
    var patrn=/^[0-9]{1,20}$/;
	if(QQ==null)
	{
		$('QQWarn').innerHTML="请输入qq号!";	
		return false;		
	}
    else if(!patrn.exec(QQ))
    {
		$('QQWarn').innerHTML="请输入正确的qq号!";
		return false;
    } 
	else
	{
		$('QQWarn').innerHTML="OK!";
		return true;	
	}
}

function CheckCellphone()
{
	var phone=document.getElementById('cellphone').value;
	//alert(phone.length);
    var patrn=/^[0-9]{1,20}$/;
	if(phone==null)
	{
		$('cellphoneWarn').innerHTML="请输入手机号码!";	
		return false;		
	}
    else if(!patrn.exec(phone))
    {
		$('cellphoneWarn').innerHTML="请输入正确的手机号码!";
		return false;
    } 
    else if(phone.length!=11)
    {
		$('cellphoneWarn').innerHTML="朋友 手机号码 应该是11位吧";
		return false;
    } 
	else
	{
		$('cellphoneWarn').innerHTML="OK!";
		return true;	
	}
}
</script>
</head>
<body>
  <div id="all">
    <div id="header">
        <div id="inner_header" class="central_fixed_width">
		    <h1 class="logor">帮帮网</h1>
            <div id="user_status"><a href="login.htm">登陆</a>||<a href="register.html">注册</a></div>
        </div>
    </div>
    
    <div id="content" class="central_fixed_width">
        
        <div class="content_parent">
            <div class="central_form" id="register">
                <div>                    
					<h1 >人人为我 我为人人</h1>
					<form action="#">
					<table>
					<tr>
						<td class="form_name">用户名：</td>
                        <td class="form_input"><input id="txtUsername" onblur="CheckUsername()" type="text" size="24" /></td>
						<td class="warning" id="nameWarn">*</td>
                    </tr>  
 					<tr>
						<td class="form_name">密码：</td>
                        <td class="form_input"><input type="password" size="24"  id="txtPwd" onblur="CheckPwd()"   /></td>
						<td id="pwdWarn" class="warning">*</td>
                    </tr>  
 					<tr>
						<td class="form_name">确认密码：</td>
                        <td class="form_input"><input type="password" size="24" id="txtPwd2" onblur="CheckPwd2()"/></td>
                        <td id="pwd2Warn" class="warning">*</td>
					</tr> 
					<tr>
						<td class="form_name">邮箱：</td>
                        <td class="form_input"><input type="text" size="24" /></td>
                    </tr>  
					<tr>
						<td class="form_name">学院：</td>
						<td class="form_input">
							<select id=college>
							<option value=''></option>
							<option value=电院 >电院</option>
							<option value=机械 >机械</option>
	  						<option value=化工 >化工</option>
							<option value=软件 >软件</option>
							</select>
						</td>
						<td id="collegeWarn" class="warning">*</td>
					</tr>
					<tr> 
						<td class="form_name"> QQ：</td>
						<td class="form_input"><input type=text size=20 maxlength=14 id='QQ' onblur="CheckQQ()"></td>
						<td id="QQWarn" class="warning"></td>				
					</tr>
					<tr> 
						<td class="form_name">手机号码：</td>
						<td class="form_input"><input type=text size=20 maxlength=14 id='cellphone' onblur="CheckCellphone()"></td>
						<td id="cellphoneWarn" class="warning"></td>
					</tr>
					<tr> 
						<td class="form_name">性别:</td>
						<td class="form_input">
							<select id='sex'>
							<OPTION value=1>男</OPTION>
							<OPTION value=2>女</OPTION>
							<OPTION value=0 selected>保密</OPTION>
							</select>
						</td>
					</tr>
					<tr> 
						<td class="form_name">情感状态:</td>
						<td class="form_input">
							<select id='emot'>
							<OPTION value=1>单身</OPTION>
							<OPTION value=2>恋爱</OPTION>
							<OPTION value=0 selected>保密</OPTION>
							</select>
						</td>
					</tr>
					<tr> 
						<td class="form_name">生日:</td>
						<td class="form_input">
							<select id=regbirthyear>
							<option value=''></option> 
							<option value=1947 >1947</option>  
							<option value=1948 >1948</option>  
							<option value=1949 >1949</option>  
							<option value=1950 >1950</option>  
							<option value=1951 >1951</option>  
							<option value=1952 >1952</option>  
							<option value=1953 >1953</option>  
							<option value=1954 >1954</option>  
							<option value=1955 >1955</option>  
							<option value=1956 >1956</option>  
							<option value=1957 >1957</option>  
							<option value=1958 >1958</option>  
							<option value=1959 >1959</option>  
							<option value=1960 >1960</option>  
							<option value=1961 >1961</option>  
							<option value=1962 >1962</option>  
							<option value=1963 >1963</option>  
							<option value=1964 >1964</option>  
							<option value=1965 >1965</option>  
							<option value=1966 >1966</option>  
							<option value=1967 >1967</option>  
							<option value=1968 >1968</option>
							<option value=1969 >1969</option>
							<option value=1970 >1970</option>
							<option value=1971 >1971</option>
							<option value=1972 >1972</option>
							<option value=1973 >1973</option>
							<option value=1974 >1974</option>
							<option value=1975 >1975</option>
							<option value=1976 >1976</option>
							<option value=1977 >1977</option>
							<option value=1978 >1978</option>
							<option value=1979 >1979</option>
							<option value=1980 >1980</option>
							<option value=1981 >1981</option>
							<option value=1982 >1982</option>
							<option value=1983 >1983</option>
							<option value=1984 >1984</option>
							<option value=1985 >1985</option>
							<option value=1986 >1986</option>
							<option value=1987 >1987</option>
							<option value=1988 >1988</option>
							<option value=1989 >1989</option>
							<option value=1990 >1990</option>
							<option value=1991 >1991</option>
							<option value=1992 >1992</option>
							<option value=1993 >1993</option>
							<option value=1994 >1994</option>
							<option value=1995 >1995</option>
							<option value=1996 >1996</option>
							<option value=1997 >1997</option>
							<option value=1998 >1998</option>
							<option value=1999 >1999</option>
							<option value=2000 >2000</option>
							</select>年 
							<select id=regbirthmonth>
							<option value=''></option>
						    <option value=1 >1</option>
						    <option value=2 >2</option>
	  						<option value=3 >3</option>
						    <option value=4 >4</option>
						    <option value=5 >5</option>
						    <option value=6 >6</option>
							<option value=7 >7</option>
						    <option value=8 >8</option>
						    <option value=9 >9</option>
						    <option value=10 >10</option>
							<option value=11 >11</option>
							<option value=12 >12</option>
							</select>月 
							<select id=regbirthday>
							<option value=''></option>
							<option value=1 >1</option>
							<option value=2 >2</option>
							<option value=3 >3</option>
							<option value=4 >4</option>
							<option value=5 >5</option>
							<option value=6 >6</option>
							<option value=7 >7</option>
							<option value=8 >8</option>  
							<option value=9 >9</option>  
							<option value=10 >10</option>  
							<option value=11 >11</option>  
							<option value=12 >12</option>  
							<option value=13 >13</option>  
							<option value=14 >14</option>  
							<option value=15 >15</option>  
							<option value=16 >16</option>  
							<option value=17 >17</option>  
							<option value=18 >18</option>  
							<option value=19 >19</option>  
							<option value=20 >20</option>  
							<option value=21 >21</option>  
							<option value=22 >22</option>  
							<option value=23 >23</option>  
							<option value=24 >24</option>  
							<option value=25 >25</option>  
							<option value=26 >26</option>  
							<option value=27 >27</option>  
							<option value=28 >28</option>  
							<option value=29 >29</option>  
							<option value=30 >30</option>  
							<option value=31 >31</option>
							</select>日</font>
						</td>
					</tr>
					<tr>
					</tr>
					<tr>		
                        <td colspan="2" align="center" ><input class="form_submit" type="button" value="注册" onclick="Register()" /></td>
                    </tr>  
					</table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    
    <div id="footer">
        <div id="inner_footer" class="central_fixed_width">


            <div class="footer_links">
                &copy; 2011 帮帮网 All rights reserved.
            </div>
            <div class="clear"></div>
            
        </div>
    </div>
  </div>
</body>
</html>

